/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package baitap;

/**
 *
 * @author Nhim
 */
public class Bai7 {
    public static void main(String[] args) {
        for(long i = 10000; i <= 9999999; i++){
            if(Thuannghich(i)) if(Csfibo(i)) if(Nguyento(i)) System.out.println(i);
        }
    }
    public static boolean Nguyento(long n){
        if(n < 2) return false;
        for(int i = 2; i <= Math.sqrt(n); i++) if(n % i == 0) return false;
        return true;
    }
    
    public static boolean Thuannghich(long n){
        long m = n, dao = 0;
        while(n > 0){
            dao = dao * 10 + n % 10;
            n = n / 10;
        }
        if(dao == m) return true;
        return false;
    }
    
    public static boolean Csfibo(long n){
        int tong = 0;
        while(n > 0){
            tong = tong + (int) (n % 10);
            n = n / 10;
        }
        if(tong == 2|| tong == 5||tong == 8||tong == 13||tong == 21||tong == 24||tong == 55) return true;
        return false;
    }
}
